﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TestXNA3.Actors;

namespace TestEditor
{
    public partial class SearchActorForm : Form
    {
        public SearchActorForm()
        {
            InitializeComponent();
            //this.Enter += new EventHandler(SearchActorForm_Enter);
            this.Activated += new EventHandler(SearchActorForm_Activated);
            foundActors.DoubleClick += new EventHandler(foundActors_DoubleClick);
            searchFilter.TextChanged += new EventHandler(searchFilter_TextChanged);
        }

        void searchFilter_TextChanged(object sender, EventArgs e)
        {
            updateFoundTimer_Tick(sender, e);
        }

        void SearchActorForm_Activated(object sender, EventArgs e)
        {
            updateFoundTimer_Tick(sender, e);
        }

        void SearchActorForm_Enter(object sender, EventArgs e)
        {
            updateFoundTimer_Tick(sender, e);
        }

        void foundActors_DoubleClick(object sender, EventArgs e)
        {
            TestEditor.StaticTestEditor.SelectActor((Actor)foundActors.SelectedItem);
        }

        public void updateFoundTimer_Tick(object sender, EventArgs e)
        {
            foundActors.Items.Clear();
            foreach (Actor a in ((EditorGameInfo)TestEditor.StaticTestEditor._game.GameInfo).Scene.Childs)
            {
                if (a.ToString().ToLower().Contains(searchFilter.Text.ToLower()))
                    foundActors.Items.Add(a);
            }
        }

        private void setProperties_Click(object sender, EventArgs e)
        {
            object[] selectedObjects = new object[foundActors.SelectedItems.Count];
            int i = 0;
            foreach (object o in foundActors.SelectedItems)
            {
                selectedObjects[i] = o;
                i++;
            }
            TestEditor.StaticTestEditor.actorProperties.SelectedObjects = selectedObjects;
        }
    }
}
